typedef struct {
  int len;
  int diameter;
  int number;
} PIPE;
int cmp(const void *p, const void *q) {
  PIPE *pa = (PIPE*)p;
  PIPE *pb = (PIPE*)q;
  if (pa->len != pb->len)
    return pb->len - pa->len;
  if (pa->diameter != pb->diameter)
    return pa->diameter - pb->diameter;
  return pb->number - pa->number;
}

void input(PIPE *p) {
  scanf("%d%d%d", &p->len, &p->diameter, &p->number);
}
PIPE p[1000];
int N, m, i, j;
int main() {
  for (scanf("%d", &N); N--;) {
    scanf("%d", &m);
    for (i = 0; i < m; i++)
      input(p + i);
    qsort(p, m, sizeof(p[0]), cmp);
    printf("%d\n", p[0].number);
  }
}
